//
//  UIColor+Extension.m
//  PageController
//
//  Created by yu on 2018/4/6.
//  Copyright © 2018年 ma c. All rights reserved.
//

#import "UIColor+Extension.h"
#import <objc/runtime.h>
static char redKey;
static char greenKey;
static char blueKey;
@implementation UIColor (Extension)

+ (UIColor *)red:(CGFloat)r green:(CGFloat)g blue:(CGFloat)b {
    return [[[UIColor alloc] init]colorWithRed:r green:g blue:b];
}

- (UIColor *)colorWithRed:(CGFloat)r green:(CGFloat)g blue:(CGFloat)b {
    UIColor *color = [UIColor colorWithRed:(r / 255.0) green:(g / 255.0) blue:(b / 255.0) alpha:1];
    [color setRed:r];
    [color setGreen:g];
    [color setBlue:b];
    return color;
}

- (void)setRed:(CGFloat)red {
    objc_setAssociatedObject(self, &redKey, [NSString stringWithFormat:@"%lf", red], OBJC_ASSOCIATION_ASSIGN);
}

- (CGFloat)red {
    return [objc_getAssociatedObject(self, &redKey) floatValue];
}


- (void)setGreen:(CGFloat)green {
    objc_setAssociatedObject(self, &greenKey, [NSString stringWithFormat:@"%lf", green], OBJC_ASSOCIATION_ASSIGN);
}

- (CGFloat)green {
    return [objc_getAssociatedObject(self, &greenKey) floatValue];
}

- (void)setBlue:(CGFloat)blue {
    objc_setAssociatedObject(self, &blueKey, [NSString stringWithFormat:@"%lf", blue], OBJC_ASSOCIATION_ASSIGN);
}

- (CGFloat)blue {
    return [objc_getAssociatedObject(self, &blueKey) floatValue];
}



+ (UIColor *)red:(CGFloat)r green:(CGFloat)g blue:(CGFloat)b alpha:(CGFloat)a {
    return [UIColor colorWithRed:r / 255.0 green:g / 255.0 blue:b / 255.0 alpha:a];
}


@end
